import 'package:finance_app/src/entities/credit_note_entity.dart';
import 'package:finance_app/src/entities/business_contact_entity.dart';

creditNoteEntityFromJson(CreditNoteEntity data, Map<String, dynamic> json) {
	if (json['data_type'] != null) {
		data.dataType = json['data_type'].toString();
	}
	if (json['id'] != null) {
		data.id = json['id'] is String
				? int.tryParse(json['id'])
				: json['id'].toInt();
	}
	if (json['company_id'] != null) {
		data.companyId = json['company_id'] is String
				? int.tryParse(json['company_id'])
				: json['company_id'].toInt();
	}
	if (json['contact_id'] != null) {
		data.contactId = json['contact_id'] is String
				? int.tryParse(json['contact_id'])
				: json['contact_id'].toInt();
	}
	if (json['invoice_id'] != null) {
		data.invoiceId = json['invoice_id'] is String
				? int.tryParse(json['invoice_id'])
				: json['invoice_id'].toInt();
	}
	if (json['number'] != null) {
		data.number = json['number'].toString();
	}
	if (json['issued_at'] != null) {
		data.issuedAt = json['issued_at'].toString();
	}
	if (json['currency_code'] != null) {
		data.currencyCode = json['currency_code'].toString();
	}
	if (json['subtotal'] != null) {
		data.subtotal = json['subtotal'] is String
				? num.tryParse(json['subtotal'])
				: json['subtotal'];
	}
	if (json['is_tax_inclusive'] != null) {
		data.isTaxInclusive = json['is_tax_inclusive'] is String
				? int.tryParse(json['is_tax_inclusive'])
				: json['is_tax_inclusive'].toInt();
	}
	if (json['tax_id'] != null) {
		data.taxId = json['tax_id'];
	}
	if (json['tax_amount'] != null) {
		data.taxAmount = json['tax_amount'] is String
				? int.tryParse(json['tax_amount'])
				: json['tax_amount'].toInt();
	}
	if (json['total'] != null) {
		data.total = json['total'] is String
				? num.tryParse(json['total'])
				: json['total'];
	}
	if (json['notes'] != null) {
		data.notes = json['notes'];
	}
	if (json['created_at'] != null) {
		data.createdAt = json['created_at'].toString();
	}
	if (json['updated_at'] != null) {
		data.updatedAt = json['updated_at'].toString();
	}
	if (json['contact'] != null) {
		data.contact = BusinessContactEntity().fromJson(json['contact']);
	}
	return data;
}

Map<String, dynamic> creditNoteEntityToJson(CreditNoteEntity entity) {
	final Map<String, dynamic> data = new Map<String, dynamic>();
	data['data_type'] = entity.dataType;
	data['id'] = entity.id;
	data['company_id'] = entity.companyId;
	data['contact_id'] = entity.contactId;
	data['invoice_id'] = entity.invoiceId;
	data['number'] = entity.number;
	data['issued_at'] = entity.issuedAt;
	data['currency_code'] = entity.currencyCode;
	data['subtotal'] = entity.subtotal;
	data['is_tax_inclusive'] = entity.isTaxInclusive;
	data['tax_id'] = entity.taxId;
	data['tax_amount'] = entity.taxAmount;
	data['total'] = entity.total;
	data['notes'] = entity.notes;
	data['created_at'] = entity.createdAt;
	data['updated_at'] = entity.updatedAt;
	data['contact'] = entity.contact?.toJson();
	return data;
}